<?php
$q=$_GET["q"];
$array= explode(",",$q);
$sym=$array[0];
$School_Id=$array[1];
$tra=$array[2];
$Access_Type=$array[3];
$Id=$Access_Type.",".$School_Id.",School_Id";
include_once '../Login/databaseconnection.php';
$tra_id=mysql_query("SELECT * FROM training WHERE Training_Name='$tra'");
if($row=mysql_fetch_array($tra_id))
{
$Training_Id=$row['Training_Id'];
}
$hint="";
$first_option="";
$nothing="";
if($sym!="Select One"&&$School_Id!="")
{
$all_tea=mysql_query("SELECT * FROM teacher WHERE School_Id='$School_Id'");
if($all_tea)
{
while($rowalltea=mysql_fetch_array($all_tea))
{
if(empty($All_Teachers))
{
$All_Teachers='"'.$rowalltea['T_NIC_Number'].'"';
}
else
{
$All_Teachers=$All_Teachers.',"'.$rowalltea['T_NIC_Number'].'"';
}
}
}
$hint=$hint."<select name='Duration' id='$School_Id' onChange='duration(this.value,this.id)' onmouseover='clearpopbox()'>";
$alldura=mysql_query("SELECT * FROM training_details");
while($rowalldura=mysql_fetch_array($alldura))
{
$Dura=$rowalldura['Duration'];
$sql="SELECT * FROM training_details WHERE Duration".$sym."'".$Dura."' AND Training_Id='".$Training_Id."' GROUP BY Teacher_NIC HAVING Teacher_NIC IN ($All_Teachers)";
$tot_tea=mysql_query($sql);
if($tot_tea)
{
if(mysql_num_rows($tot_tea)>0)
{
$nothing="false";
$hint=$hint.'<option value="'.$Dura.'">'.$Dura.'</option>';
if(empty($first_option))
{
$first_option=$Dura;
}
}
}
}
if($nothing!="false")
{
$hint=$hint.'<option value="">No result</option>';
}
$tot_f_tea=mysql_query("SELECT * FROM teacher WHERE (Gender='Female' OR Gender='female') AND School_Id='$School_Id'");
if($tot_f_tea)
{
while($row_fe_tea=mysql_fetch_array($tot_f_tea))
{
if(empty($Female_Teachers))
{
$Female_Teachers='"'.$row_fe_tea['T_NIC_Number'].'"';
}
else
{
$Female_Teachers=$Female_Teachers.',"'.$row_fe_tea['T_NIC_Number'].'"';
}
}
}
$tot_m_tea=mysql_query("SELECT * FROM teacher WHERE (Gender='Male' OR Gender='male') AND School_Id='$School_Id'");
if($tot_m_tea)
{
while($row_ma_tea=mysql_fetch_array($tot_m_tea))
{
if(empty($Male_Teachers))
{
$Male_Teachers='"'.$row_ma_tea['T_NIC_Number'].'"';
}
else
{
$Male_Teachers=$Male_Teachers.',"'.$row_ma_tea['T_NIC_Number'].'"';
}
}
}
if($first_option!="")
{
$fir_val_male=mysql_query("SELECT COUNT(DISTINCT(Teacher_NIC)) AS males FROM training_details WHERE Duration".$sym."'".$first_option."' AND Training_Id='".$Training_Id."' GROUP BY Teacher_NIC HAVING Teacher_NIC in ($Male_Teachers)");
if($fir_val_male)
{
if($row_fir_mval=mysql_fetch_array($fir_val_male))
{
$Tra_Male_Teachers=$row_fir_mval['males'];
}
}

$fir_val_female=mysql_query("SELECT COUNT(DISTINCT(Teacher_NIC)) AS females FROM training_details WHERE Duration".$sym."'".$first_option."' AND Training_Id='".$Training_Id."' GROUP BY Teacher_NIC HAVING Teacher_NIC in ($Female_Teachers)");
if($fir_val_female)
{
if($row_fir_fval=mysql_fetch_array($fir_val_female))
{
$Tra_Female_Teachers=$row_fir_fval['females'];
}
}
}
$hint=$hint.'</select>
<label> :</label><div id="byduration">
<table height="105" class="imgholder1">  
              <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
         <tr>
        <th> </th>
         <td></td>
         </tr>
		 <tr>
		 <th>        
         <label>Number of male teachers:</label>
         </th>
         <td>';
		 if($Tra_Male_Teachers=="")
		 {
		 $Tra_Male_Teachers="0";
		 }
		 if($Tra_Female_Teachers=="")
		 {
		 $Tra_Female_Teachers="0";
		 }
if($Tra_Male_Teachers!="0")
{
$hint=$hint."<input type='text' name='Tra_Male_Teachers' value='$Tra_Male_Teachers' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Tra_Male_Teachers' value='$Tra_Male_Teachers' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint.'</td>
         </tr>   
       <tr>
        <th>        
         <label>Number of female teachers:</label>
         </th>
         <td>';
if($Tra_Female_Teachers!="0")
{
$hint=$hint."<input type='text' name='Tra_Female_Teachers' value='$Tra_Female_Teachers' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Tra_Female_Teachers' value='$Tra_Female_Teachers' readonly='readonly' onmouseover='clearpopbox()'/></td>
}
         </tr></table></div>";
}

if($hint=="")
{
if($School_Id=="")
{
$response="<font color='red'>*Please select a school!</font>";
}
$response=$response."<select name='Duration' id='$School_Id' onChange='duration(this.value,this.id)'><option value=''>No result</option></select>
<label> :</label>";
$response=$response.'<div id="byduration">
<table height="105" class="imgholder1">  
              <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
         <tr>
        <th> </th>
         <td></td>
         </tr>
		 <tr>
		 <th>             
         <label>Number of male teachers:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='Tra_Male_Teachers' readonly='readonly'/>";
$response=$response.'</td>
         </tr>   
       <tr>
        <th>        
         <label>Number of female teachersv:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='Tra_Female_Teachers' readonly='readonly'/></td>
         </tr></table></div>";
}
else
{
$response=$hint;
}
echo $response;
?>